package com.liuchang.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author :liuchang
 * @description:TODO
 * @date :2021/8/7 0:01
 */
@EnableSwagger2
@EnableSwaggerBootstrapUI
@Configuration
public class SwaggerConfig {

    @Value("${service.url}")
    private String serviceUrl;

    @Value("${server.port}")
    private String servicePort;

    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .host(serviceUrl + ":" + servicePort)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.liuchang.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("FastDFS RESTful APIs")
                .description("操作FastDFS文件")
                .termsOfServiceUrl(serviceUrl + ":"+ servicePort +"/api/fastdfs")
                .contact(new Contact("liuchang", serviceUrl + ":"+ servicePort + "/api/fastdfs", "lc15072845597@163.com"))
                .version("1.0")
                .build();

    }
}
